package com.yc.web.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oyj.dao.DBHelper;
@WebServlet("/admin")
public class AdminServlet extends BasicServlet {
	DBHelper db = new DBHelper();
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/plain;charset=utf-8");
		
		//得到op
		String op = req.getParameter("op");
		if("login".equals(op)){
			login(req,resp);
		}
	}

	private void login(HttpServletRequest req, HttpServletResponse resp) {
		String uname = req.getParameter("uname");
		String pwd = req.getParameter("pwd");
		
		String sql = "select * from admininfo where aname = ? and pwd = md5(?) and status = 1";
		List<Map<String, Object>> list = db.findAll(sql, uname,pwd);
		 if( list.size() > 0 ){
			 req.getSession().setAttribute("AdminUser", list.get(0));
			 this.send(resp, 1);
		 }else{
			 this.send(resp, -1);
		 }
	}

}
